package com.quick.domain;

import lombok.Cleanup;
import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.Jedis;

/**
 * @Cleanup注解能够自动释放资源。
 * Created by wangxin332 on 2018/5/13.
 */
@Slf4j
public class UseCleanup {
    public void jedisExample(String[] args){
        try {
            @Cleanup Jedis jedis = redisService.getJedis();
        }catch (Exception e){
            log.error("异常",e);
        }
    }

    //相当与以下代码
    public void jedisExample1(String[] args){
        Jedis jedis= null;
        try {
            jedis = redisService.getJedis();
        }catch (Exception e){
            log.error("异常",e);
        }finally {
            if (jedis != null) {
                try {
                    jedis.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
